<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Admin_Index extends Controller_Admin_Base
{
    public function action_index()
    {        
        Request::current()->redirect(Helper_Admin::get_url() . '/products/reviews');
    }
    
    public function action_profile()
    {       
        if (HTTP_Request::POST == $this->request->method()) {
            $email      = $this->request->post('email');
            $password   = $this->request->post('password');
            $repassword = $this->request->post('repassword');
                  
            try {
                if ($password && (trim($password) == trim($repassword))) {
                    // TODO может надо что
                } else {
                    $password = null;
                }
                Model_Auth::instance()->get_user()->edit_user($email, $password);
                $this->add_message('Сохранено');                      
            } catch (Model_Exception $e) {
                $this->add_message($e->getMessage());
            }
        }
        $content = new View('admin/index/profile_tpl');       
        $this->print_template('Настройка профиля', $content);  
    }
    
    public function action_shop()
    {
        if (HTTP_Request::POST == $this->request->method()) {
            $name      = $this->request->post('name');
            $url       = $this->request->post('url');
            $parse_url = $this->request->post('parse_url');
                  
            try {
                ORM::factory('shop')->get_current()->edit_shop($name, $url, $parse_url);
                $this->add_message('Сохранено');                      
            } catch (Model_Exception $e) {
                $this->add_message($e->getMessage());
            }
        }
        $content = new View('admin/index/shop_tpl');       
        $this->print_template('Настройка магазина', $content);    
    }
    
    public function action_start()
    {
        $content = new View('admin/index/start_tpl');       
        $this->print_template('Начало работы', $content);   
    }
} 
